/*   1:    */ package org.intellij.plugins.relaxNG.validation;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.daemon.Validator.ValidationHost;
import com.intellij.codeInsight.daemon.Validator.ValidationHost.ErrorType;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.thaiopensource.util.PropertyMapBuilder;
import com.thaiopensource.validate.Schema;
import com.thaiopensource.validate.ValidateProperty;
import com.thaiopensource.validate.Validator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */ 
/*  25:    */ public class XmlInstanceValidator
/*  26:    */ {
/*  27: 45 */   private static final Logger a = Logger.getInstance("org.intellij.plugins.relaxNG.validation.XmlInstanceValidator");
/*  28:    */   
/*  29:    */   public static void doValidation(@NotNull XmlDocument paramXmlDocument, Validator.ValidationHost paramValidationHost, XmlFile paramXmlFile)
/*  30:    */   {
/*  31: 52 */     if (paramXmlDocument == null) {
/*  32: 52 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/validation/XmlInstanceValidator", "doValidation" }));
/*  33:    */     }
/*  34:    */     try
/*  35:    */     {
/*  36: 52 */       Schema localSchema = RngParser.getCachedSchema(paramXmlFile);
/*  37: 53 */       if (localSchema == null) {
/*  38: 55 */         return;
/*  39:    */       }
/*  40: 58 */       ErrorHandler localErrorHandler = MyErrorHandler.create(paramXmlDocument, paramValidationHost);
/*  41: 59 */       if (localErrorHandler == null) {
/*  42: 60 */         return;
/*  43:    */       }
/*  44: 63 */       PropertyMapBuilder localPropertyMapBuilder = new PropertyMapBuilder();
/*  45: 64 */       localPropertyMapBuilder.put(ValidateProperty.ERROR_HANDLER, localErrorHandler);
/*  46:    */       
/*  47: 66 */       ContentHandler localContentHandler = localSchema.createValidator(localPropertyMapBuilder.toPropertyMap()).getContentHandler();
/*  48: 67 */       paramXmlDocument.accept(new Psi2SaxAdapter(localContentHandler));
/*  49:    */     }
/*  50:    */     catch (ProcessCanceledException localProcessCanceledException)
/*  51:    */     {
/*  52: 70 */       throw localProcessCanceledException;
/*  53:    */     }
/*  54:    */     catch (RuntimeException localRuntimeException)
/*  55:    */     {
/*  56: 72 */       a.error(localRuntimeException);
/*  57:    */     }
/*  58:    */     catch (Exception localException)
/*  59:    */     {
/*  60: 74 */       a.info(localException);
/*  61:    */     }
/*  62:    */   }
/*  63:    */   
/*  64:    */   private static class MyErrorHandler
/*  65:    */     implements ErrorHandler
/*  66:    */   {
/*  67:    */     private final Validator.ValidationHost a;
/*  68:    */     private final Document b;
/*  69:    */     private final PsiFile c;
/*  70:    */     
/*  71:    */     private MyErrorHandler(XmlDocument paramXmlDocument, Validator.ValidationHost paramValidationHost)
/*  72:    */     {
/*  73: 84 */       this.a = paramValidationHost;
/*  74: 85 */       this.c = paramXmlDocument.getContainingFile();
/*  75: 86 */       this.b = PsiDocumentManager.getInstance(this.c.getProject()).getDocument(this.c);
/*  76:    */     }
/*  77:    */     
/*  78:    */     public void warning(SAXParseException paramSAXParseException)
/*  79:    */       throws SAXException
/*  80:    */     {
/*  81: 91 */       RngSchemaValidator.handleError(paramSAXParseException, this.c, this.b, new RngSchemaValidator.ValidationMessageConsumer()
/*  82:    */       {
/*  83:    */         public void onMessage(PsiElement paramAnonymousPsiElement, String paramAnonymousString)
/*  84:    */         {
/*  85: 94 */           XmlInstanceValidator.MyErrorHandler.this.a.addMessage(paramAnonymousPsiElement, paramAnonymousString, Validator.ValidationHost.ErrorType.WARNING);
/*  86:    */         }
/*  87:    */       });
/*  88:    */     }
/*  89:    */     
/*  90:    */     public void error(SAXParseException paramSAXParseException)
/*  91:    */       throws SAXException
/*  92:    */     {
/*  93:101 */       RngSchemaValidator.handleError(paramSAXParseException, this.c, this.b, new RngSchemaValidator.ValidationMessageConsumer()
/*  94:    */       {
/*  95:    */         public void onMessage(PsiElement paramAnonymousPsiElement, String paramAnonymousString)
/*  96:    */         {
/*  97:104 */           XmlInstanceValidator.MyErrorHandler.this.a.addMessage(paramAnonymousPsiElement, paramAnonymousString, Validator.ValidationHost.ErrorType.ERROR);
/*  98:    */         }
/*  99:    */       });
/* 100:    */     }
/* 101:    */     
/* 102:    */     public void fatalError(SAXParseException paramSAXParseException)
/* 103:    */       throws SAXException
/* 104:    */     {
/* 105:111 */       RngSchemaValidator.handleError(paramSAXParseException, this.c, this.b, new RngSchemaValidator.ValidationMessageConsumer()
/* 106:    */       {
/* 107:    */         public void onMessage(PsiElement paramAnonymousPsiElement, String paramAnonymousString)
/* 108:    */         {
/* 109:114 */           XmlInstanceValidator.MyErrorHandler.this.a.addMessage(paramAnonymousPsiElement, paramAnonymousString, Validator.ValidationHost.ErrorType.ERROR);
/* 110:    */         }
/* 111:    */       });
/* 112:    */     }
/* 113:    */     
/* 114:    */     @Nullable
/* 115:    */     public static ErrorHandler create(XmlDocument paramXmlDocument, Validator.ValidationHost paramValidationHost)
/* 116:    */     {
/* 117:121 */       XmlTag localXmlTag = paramXmlDocument.getRootTag();
/* 118:122 */       if (localXmlTag == null) {
/* 119:123 */         return null;
/* 120:    */       }
/* 121:125 */       return new MyErrorHandler(paramXmlDocument, paramValidationHost);
/* 122:    */     }
/* 123:    */   }
/* 124:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.validation.XmlInstanceValidator

 * JD-Core Version:    0.7.0.1

 */